package com.qingcheng.controller.order;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.service.order.CategoryReportService;
import com.qingcheng.service.order.OrderService;
import com.qingcheng.service.order.TradeReportService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 定时任务解决方案
 */
@Component
public class OrderTask {

    @Reference
    private OrderService orderService;

    @Reference
    private CategoryReportService categoryReportService;

    @Reference
    private TradeReportService tradeReportService;

    /**
     * 超时订单关闭
     */
    @Scheduled(cron = "0 0/2 * * * ?")
    public void orderTimeOutLogic(){ //每两分钟间隔执行一次任务
        System.out.println(new Date());
        orderService.orderTimeOutLogic();
    }

    /**
     * 商品类目每天统计数据
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void createCategoryReportData(){
        System.out.println("生成类目统计数据");
        categoryReportService.createData();
    }

    /**
     * 订单交易每天统计数据
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void createTradeReportData(){
        System.out.println("生成交易统计数据");
        tradeReportService.createData();
    }
}
